import * as mobx from 'mobx';
import { observable, action, useStrict, computed, asMap } from 'mobx';
import { chooseExceptionOperator } from '../apis/req';
import { getComsMobx } from '../util/convert';

export class EhOperatorStore{

    baseParams = {};
    fields = [];
    @observable ehform = null;
    callBackEvent = null;

    constructor(){
        this.setBaseParams = this.setBaseParams;
        this.doInit = this.doInit;
        this.setCallBackEvent = this.setCallBackEvent;
        this.doCancel = this.doCancel;
    }

    @action
    setBaseParams = (params={}) => {
        this.baseParams = params;
    }

    doInit = () =>{
        chooseExceptionOperator(this.baseParams).then(data =>{
            const { fields,formValue } = data;
            this.fields = fields;
            const { WeaForm } = getComsMobx();
            this.ehform = new WeaForm();
            this.ehform.initFormFieldObj(fields);
            this.ehform.updateFields(formValue);
        });
    }

    setCallBackEvent = (fun) => {
        this.callBackEvent = fun;
    }

    doCancel = () => {
        let ehparams = {eh_setoperator:"n", isFirstSubmit:1, ehnextnodeid:this.baseParams.ehnextnodeid};
        this.callBackEvent(ehparams);
    }

}